package com.itheima.dao;

import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CheckgroupCheckitemDao {

    @Select("select count(cm.id) from t_checkitem cm, t_checkgroup cp, t_checkgroup_checkitem cpm " +
            "where cm.id = cpm.checkitem_id and cp.id = cpm.checkgroup_id " +
            "and cm.id = #{id}")
    Integer getByCheckItemId(Integer id);

    @Insert("insert into t_checkgroup_checkitem(checkgroup_id, checkitem_id) values " +
            "(#{checkGroupId},#{checkitemId})")
    void insert(Integer checkGroupId, Integer checkitemId);

    @Select("select count(*) from t_checkgroup_checkitem " +
            "where checkgroup_id = #{id}")
    Integer getByCheckgroupId(Integer id);

    @Delete("delete from t_checkgroup_checkitem where checkgroup_id = #{id}")
    void deleteByCheckgroupId(Integer id);

    @Select("select cm.id from t_checkitem cm, t_checkgroup cp, t_checkgroup_checkitem cpm " +
            "where cm.id = cpm.checkitem_id and cp.id = cpm.checkgroup_id " +
            "and cp.id = #{checkgroupId}")
    List<Integer> find(Integer checkgroupId);
}
